package com.ruoyi.web.controller.shop.common;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.shop.goods.domain.ShopGoods;
import com.ruoyi.shop.goods.service.IShopGoodsService;
import com.ruoyi.shop.service.IShopIndexService;

import cn.hutool.json.JSONArray;

/**
 * 商品首页Controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */
@Controller
public class ShopIndexController extends BaseController {

	@Autowired
	private IShopIndexService shopIndexService;
	@Autowired
	private IShopGoodsService shopGoodsService;

	/**
	 * 首页表格数据
	 * 
	 * @param mmap
	 * @return
	 */
	@GetMapping("/shop/main")
	public String main(ModelMap mmap) {
		// 热销商品
		List<ShopGoods> topGoods = shopGoodsService.queryTopList(5);
		mmap.put("topGoods", topGoods);
		// 登录排行
		JSONArray topLogins = shopIndexService.selectTopLogin(5);
		mmap.put("topLogins", topLogins);
		return "shop/main";
	}

	/**
	 * 首页展示数据
	 * 
	 * @return
	 */
	@GetMapping("/shop/main/data")
	@ResponseBody
	public AjaxResult main() {
		return success(shopIndexService.getIndexData());
	}

}
